﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Coldairarrow.Business.Goods;
using Coldairarrow.Entity.Goods;
using Coldairarrow.Util;
using Microsoft.AspNetCore.Mvc;

namespace Coldairarrow.Api.Controllers.backstage
{

    [Route("/backstage/[controller]/[action]")]
    public class BKS_SupplierController : BaseApiController
    {
        #region DI

        public BKS_SupplierController(IBTB_SupplierBusiness bTB_SupplierBus)
        {
            _bTB_SupplierBus = bTB_SupplierBus;
        }

        IBTB_SupplierBusiness _bTB_SupplierBus { get; }

        #endregion
        /// <summary>
        /// 查看所有供货商----分页
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<PageResult<BTB_Supplier>> GetDataList(PageInput<ConditionDTO> input)
        {
            return await _bTB_SupplierBus.GetDataListAsync(input);
        }
        /// <summary>
        /// 查询所有供货商
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public async Task<List<BTB_Supplier>> GetAll()
        {
            return await _bTB_SupplierBus.GetAll();
        }

        /// <summary>
        /// 查看指定供货商
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<BTB_Supplier> GetTheData(IdInputDTO input)
        {
            return await _bTB_SupplierBus.GetTheDataAsync(input.id);
        }

        /// <summary>
        /// 添加或修改供货商
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task SaveData(BTB_Supplier data)
        {
            if (data.id.IsNullOrEmpty())
            {
                InitEntity(data);

                await _bTB_SupplierBus.AddDataAsync(data);
            }
            else
            {
                await _bTB_SupplierBus.UpdateDataAsync(data);
            }
        }

        /// <summary>
        /// 删除指定供货商
        /// </summary>
        /// <param name="ids"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task DeleteData(List<string> ids)
        {
            await _bTB_SupplierBus.DeleteDataAsync(ids);
        }
    }
}
